package com.dong.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.util.StringValueResolver;

public class Red implements ApplicationContextAware, BeanNameAware , EmbeddedValueResolverAware {
    private ApplicationContext applicationContext;
    private StringValueResolver stringValueResolver;
    @Override
    public void setBeanName(String name) {
        System.out.println("bean的名字 是  "+name);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("传入的 ioc"+ applicationContext);
        this.applicationContext=applicationContext;
    }

    /**
     * 解析占位符
     * @param resolver
     */
    @Override
    public void setEmbeddedValueResolver(StringValueResolver resolver) {
        this.stringValueResolver=resolver;
        String result = resolver.resolveStringValue("你好 ${os.name} ,我是 #{20*18}");
        System.out.println("解析的字符串: "+result);
    }
}
